package org.dromara.plotInfo.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.plotInfo.domain.vo.LandPlotInfoVo;
import org.dromara.plotInfo.domain.bo.LandPlotInfoBo;
import org.dromara.plotInfo.service.ILandPlotInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 地块查询
 *
 * @author Lion Li
 * @date 2024-12-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/plotInfo/plotInfo")
public class LandPlotInfoController extends BaseController {

    private final ILandPlotInfoService landPlotInfoService;

    /**
     * 查询地块查询列表
     */
    @SaCheckPermission("plotInfo:plotInfo:list")
    @GetMapping("/list")
    public TableDataInfo<LandPlotInfoVo> list(LandPlotInfoBo bo, PageQuery pageQuery) {
        return landPlotInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出地块查询列表
     */
    @SaCheckPermission("plotInfo:plotInfo:export")
    @Log(title = "地块查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(LandPlotInfoBo bo, HttpServletResponse response) {
        List<LandPlotInfoVo> list = landPlotInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "地块查询", LandPlotInfoVo.class, response);
    }

    /**
     * 获取地块查询详细信息
     *
     * @param plotId 主键
     */
    @SaCheckPermission("plotInfo:plotInfo:query")
    @GetMapping("/{plotId}")
    public R<LandPlotInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long plotId) {
        return R.ok(landPlotInfoService.queryById(plotId));
    }

    /**
     * 新增地块查询
     */
    @SaCheckPermission("plotInfo:plotInfo:add")
    @Log(title = "地块查询", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LandPlotInfoBo bo) {
        return toAjax(landPlotInfoService.insertByBo(bo));
    }

    /**
     * 修改地块查询
     */
    @SaCheckPermission("plotInfo:plotInfo:edit")
    @Log(title = "地块查询", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LandPlotInfoBo bo) {
        return toAjax(landPlotInfoService.updateByBo(bo));
    }

    /**
     * 删除地块查询
     *
     * @param plotIds 主键串
     */
    @SaCheckPermission("plotInfo:plotInfo:remove")
    @Log(title = "地块查询", businessType = BusinessType.DELETE)
    @DeleteMapping("/{plotIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] plotIds) {
        return toAjax(landPlotInfoService.deleteWithValidByIds(List.of(plotIds), true));
    }
}
